package com.cardvalue.sys.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.cardvalue.sys.R;
import com.cardvalue.sys.adapter.MoreAdapter;
import com.cardvalue.sys.base.BaseFragment;
import com.cardvalue.sys.entity.MoreListDto;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnItemClick;

/**
 * 更多的页面
 * Created by cardvalue on 2016/4/1.
 */
public class MoreFragment extends BaseFragment {
    private List<MoreListDto> mMoreListDto= new ArrayList<>();
    private View view;
    private MoreAdapter mMoreAdapter;
    private RelativeLayout as;
    @Bind(android.R.id.list) ListView mListView;
    private int [] icons={R.mipmap.share,R.mipmap.pruoduce,R.mipmap.honor,
            R.mipmap.contact,R.mipmap.about,R.mipmap.feedback,R.mipmap.service,R.mipmap.service};
    private String[] title={"融资攻略","公司简介","资质荣誉","联系方式","关于小企额","意见反馈","在线客服"};
    private String[] activity={"","","","","com.cardvalue.sys.activity.AboutActivity","com.cardvalue.sys.activity.FeedBackActivity",
            "com.cardvalue.sys.activity.CustomerServiceActivity"};
    private String[] url={};
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.fragment_more,container,false);
        ButterKnife.bind(this,view);
        LayoutInflater  inflater1=LayoutInflater.from(getActivity());
        View  viewHead=inflater1.inflate(R.layout.list_more_head,null);
        as=(RelativeLayout)viewHead.findViewById(R.id.as);
        for(int i=0;i<title.length;i++){
            MoreListDto item=new MoreListDto();
            item.setTitle(title[i]);
            item.setIconIndex(icons[i]);
            item.setActivity(activity[i]);
            if (i == 0 || i == 1) {
                item.setShow(true);
            }
            mMoreListDto.add(item);
        }
        mMoreAdapter = new MoreAdapter(getActivity(),mMoreListDto);
        mListView.addHeaderView(viewHead);
        mListView.setDivider(null);
        mListView.setAdapter(mMoreAdapter);
        return view;
    }

       @OnItemClick(android.R.id.list) void OnItemClickList(int position){
           MoreListDto item=(MoreListDto)mListView.getItemAtPosition(position);
           if(!item.getActivity().equals("")){
               try {
                   Intent   intent = new Intent(getActivity(),Class.forName(item.getActivity().toString()));
                   startActivity(intent);
               } catch (ClassNotFoundException e) {
                   e.printStackTrace();
               }
           }


       }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        setHeaderFields(0, R.string.more,0,0, 0,0);
        super.onActivityCreated(savedInstanceState);
    }
}
